package com.example.todolist.controller;


import com.example.todolist.common.CheckLogin;
import com.example.todolist.dto.business.WriteCommentsDTO;
import com.example.todolist.response.BaseResponse;
import com.example.todolist.service.DynamicCommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-02-25
 */
@Api(tags = "动态评论")
@CrossOrigin
@RestController
@RequestMapping("/dynamic-comments")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DynamicCommentsController {

    private final DynamicCommentsService dynamicCommentsService;

    @CheckLogin
    @ApiOperation("写评论")
    @PostMapping("/writeComments")
    public BaseResponse writeComments(@RequestBody WriteCommentsDTO writeCommentsDto){
        return dynamicCommentsService.writeComments(writeCommentsDto);
    }

    @CheckLogin
    @ApiOperation("是否能够删除这条评论")
    @GetMapping("/whetherCanDeleteThisComments")
    public BaseResponse whetherCanDeleteThisComments(String commentId){
        return dynamicCommentsService.whetherCanDeleteThisComments(commentId);
    }

    @CheckLogin
    @ApiOperation("删除评论")
    @PostMapping("/deleteComments")
    public BaseResponse deleteComments(String commentId,String dynamicId){
        return dynamicCommentsService.deleteComments(commentId,dynamicId);
    }

}

